//
//  FZMainViewController.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/19/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit
import SnapKit

class FZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let fzTabBar: FZTabBar = FZTabBar()
//        fzTabBar.fzDelegate = self
        //给fzTabBar的闭包赋值，达到点击按钮可以modal个控制器出来
        fzTabBar.composeButtonClosure = {
            
            let composeView = FZComposeView()
            composeView.showCompose(self)
            
        }
        //更改默认的tabBar
        self.setValue(fzTabBar, forKey: "tabBar")
        addChildViewController(FZHomeViewController.init(), title: "首页", imageName: "tabbar_home")
        addChildViewController(FZMessageViewController.init(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(FZDiscoverViewController.init(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(FZProfileViewController.init(), title: "我", imageName: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        vc.title = title;
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected);
        vc.tabBarItem.image = UIImage(named:imageName);
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
        self.addChildViewController(UINavigationController(rootViewController: vc));
    }
}

//extension FZMainViewController: FZTabBarDelegate{
////    func composeButtonClick() {
////        print("点击了啊啊啊啊啊啊啊")
////    }
//}
